package pubsub

import (
	"fmt"
	"math"
	"os"
)

func traingleArea(data [3]float64) float64 {
	a, b, c := data[0], data[1], data[2]
	p := (a + b + c) / 2
	s1 := p - a
	s2 := p - b
	s3 := p - c
	sub1 := p * s1 * s2 * s3
	area := math.Sqrt(sub1)
	return area
}
func RunFuncData() {
	data := [][3]float64{
		{1195, 2185, 2050},
		{785, 2185, 1880},
		{1210, 1113, 805},
		{1068, 1655, 1105},
		{1762, 1685, 1117},
		{1170, 1800, 1705},
		{1890, 1193, 1688},
		{1205, 2025, 2160},
		{1940, 1470, 941},
		{1130, 1455, 1490},
		{1170, 1460, 870},
		{845, 1250, 1170},
		{1075, 836, 1080},
		{1835, 1100, 1105},
		{915, 1565, 2015},
	}
	// str := ""
	var res float64 = 0
	fd, _ := os.OpenFile("res.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	defer fd.Close()
	for idx, val := range data {
		fmt.Fprintf(fd, "\n\n第%d个三角形", idx+1)
		fmt.Fprintln(fd, "输入的值")
		fmt.Fprintln(fd, val)
		// str += "\n\n第个三角形"
		if ok := checkoutTraingle(val); ok {
			fmt.Fprintln(fd, "输出的值")
			fmt.Fprintf(fd, "val = %.4f", traingleArea(val))
			res += traingleArea(val)
		}
	}
	fmt.Fprintf(fd, "\n最终总合面积为res = %.4f", res)
}
func checkoutTraingle(data [3]float64) bool {
	if data[0]+data[1] < data[2] || data[0]+data[2] < data[1] || data[1]+data[2] < data[0] {
		return false
	}
	return true
}
